<template>
    <div>
        <city-header></city-header>
        <city-search :cities="cities"></city-search>
        <city-list :hotCities="hotCities" :cities="cities" :letter="letter"></city-list>
        <alphabet :cities="cities" @change="handleLetterChange"></alphabet>
    </div>
</template>
<script>
import CityHeader from "./components/Header"
import CitySearch from "./components/Search"
import CityList from "./components/List"
import Alphabet from "./components/Alphabet"
import axios from 'axios'
export default {
    name:'City',
    data:function(){
        return{
            cities:{},
            hotCities:[],
            letter:"",
        }
    },
    components:{
        CityHeader:CityHeader,
        CitySearch:CitySearch,
        CityList:CityList,
        Alphabet:Alphabet
    },
    mounted:function(){
        this.getCityList();
    },
    methods:{
        getCityList:function(){
            axios.get('/static/mock/city.json')
            .then(this.getCityListSucc)
        },
        getCityListSucc:function(res){
            res = res.data;
            if(res.ret && res.data){
                const data = res.data;
                this.hotCities = data.hotCities;
                this.cities = data.cities;
            }
        },
        handleLetterChange:function(letter){
            this.letter = letter;
        }
    }
}
</script>
<style lang="scss" scoped>

</style>